/*
 * ImageUtil.cpp
 *
 *  Created on: Jul 12, 2009
 *      Author: kurt
 */

#include "ImageUtil.h"
#include <GL/gl.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
using namespace objdraw;

int ImageUtil::getNextPower2(int width)
{
	int b = width;
	int n;
	for (n = 0; b != 0; n++) b >>= 1;
		b = 1 << n;
	if (b == 2 * width)
		b >>= 1;
	return b;
}
bool ImageUtil::IsPower2(int x)
{ 
	return ( (x > 0) && ((x & (x - 1)) == 0) ); 
}

Image * ImageUtil::loadImageFile(string file, DrawingCanvas * canvas)
{
	return loadImageFile(file,rgba,canvas);
}

Image * ImageUtil::loadImageFile(std::string file, PixelFormat pixelFormat, DrawingCanvas * canvas)
{
	if(is_png(file))
		return loadImageFilePNG(file, pixelFormat, canvas);
//	TODO add more here
	return NULL;
}
